package com.example.lenovo.listvitesqlite;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class EditActivity extends AppCompatActivity {
    private EditText edtNo;
    private EditText edtName;
    private EditText edtAge;
    private Button btnOK;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_edit);

        initView();

        //拿到主方法传来的学生信息并且显示到活动页面
        String stuno = getIntent().getStringExtra("NO");
        String name = getIntent().getStringExtra("NAME");
        int age = getIntent().getIntExtra("AGE",0);

        edtNo.setText(stuno);
        edtName.setText(name);
        edtAge.setText(String.valueOf(age));

        btnOK.setOnClickListener(new View.OnClickListener() {
            @Override
            //获取用户编辑后的信息传回给主页面
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.putExtra("NO",edtNo.getText().toString());
                intent.putExtra("NAME",edtName.getText().toString());
                intent.putExtra("AGE",Integer.parseInt(edtAge.getText().toString()));

                setResult(2003,intent);
                finish();
            }
        });

    }

    private void initView() {
        edtNo =findViewById(R.id.edtN0);
        edtName =findViewById(R.id.edtName);
        edtAge =findViewById(R.id.edtAge);
        btnOK = findViewById(R.id.btn_ok);
    }
}